from datetime import datetime

from django.db import models

from DjangoUeditor.models import UEditorField
from apps.users.models import BaseModel, UserProfile


# Create your models here.
class BlogTag(BaseModel):
    tag = models.CharField(max_length=10, verbose_name=u'标签')

    class Meta:
        verbose_name = "博客标签"
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.tag
    def message_nums(self):
        return self.blogmessage_set.all().count()


class BlogMessage(BaseModel):
    author = models.ForeignKey(UserProfile, on_delete=models.CASCADE, verbose_name="作者")
    name = models.CharField(verbose_name="文章名称", max_length=50)
    desc = models.CharField(verbose_name="文章描述", max_length=300,default='')
    detail = UEditorField(verbose_name='内容', height=500, width=800,
                           default=u'', imagePath="Article_img/%%Y/%%m/",
                           toolbars='full', filePath='Article_file/%%Y/%%m/',
                           upload_settings={"imageMaxSize": 12040000},
                           settings={}, command=None,)
    click_nums = models.IntegerField(default=0, verbose_name='浏览次数')
    last_time = models.DateTimeField(default=datetime.now,verbose_name="修改时间")
    tag = models.ForeignKey(BlogTag, on_delete=models.CASCADE, verbose_name="标签")
    class Meta:
        verbose_name = "博客文章"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name
    def comment_nums(self):
        return self.blogcomments_set.all().count()


class AboutMessage(BaseModel):
    author = models.ForeignKey(UserProfile, on_delete=models.CASCADE, verbose_name="作者")
    name = models.CharField(verbose_name="文章名称", max_length=50)
    desc = models.CharField(verbose_name="文章描述", max_length=300,default='')
    detail = UEditorField(verbose_name='内容', height=500, width=800,
                           default=u'', imagePath="Article_img/%%Y/%%m/",
                           toolbars='full', filePath='Article_file/%%Y/%%m/',
                           upload_settings={"imageMaxSize": 1204000},
                           settings={}, command=None,)
    click_nums = models.IntegerField(default=0, verbose_name='浏览次数')
    last_time = models.DateTimeField(default=datetime.now,verbose_name="修改时间")
    class Meta:
        verbose_name = "关于我"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name